package zoom;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Test2 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());
        Map<String, Set<String>> map = new HashMap<>();
        for (int i = 0; i < q; i++) {
            String[] s = br.readLine().split(" ");
            String name = s[1];
            if (s.length == 3){
                // 用户注册
                Set<String> set = new HashSet<>(Arrays.asList(br.readLine().split(" ")));
                map.put(name, set);
            }else if (s.length == 2){
                // 用户查询，这里需要递归添加
                if (!map.containsKey(name)) System.out.println("error");
                else {
                    Set<String> temp = new HashSet<>(map.get(name));
                    int start = temp.size();
                    Set<String> visited = new HashSet<>();
                    visited.add(name);
                    boolean flag = true;
                    while (flag) {
                        flag = false;
                        for (String key : map.keySet()){
                            if (flag) break;
                            if (visited.contains(key)) continue;
                            for (String subscribe : temp){
                                if (map.get(key).contains(subscribe)) {
                                    temp.addAll(map.get(key));
                                    visited.add(key);
                                    flag = true;
                                    break;
                                }
                            }
                        }
                    }
                    System.out.println(temp.size() - start);
                }
            }
        }
    }
}
